﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Core;

namespace DAL.Connect
{
    public static class Link
    {
        private static string BuildAbsolute(string relativeUrl)
        {
            Uri uri = HttpContext.Current.Request.Url;
            string app = HttpContext.Current.Request.ApplicationPath;
            if (!app.EndsWith("/"))
                app += "/";
            relativeUrl = relativeUrl.TrimStart('/');
            return HttpUtility.UrlPathEncode(String.Format("http://{0}:{1}{2}{3}", uri.Host, uri.Port, app, relativeUrl));
        }
        #region he thong
        public static string DenMenu(string theLoai, string chuDeID)
        {
            return BuildAbsolute(String.Format("DanhSachBaiDang.aspx?TheLoaiID={0}&ChuDeID={1}", theLoai, chuDeID));
        }

        public static string DenTrangTimKiem(string chuoiTimKiem, string trang)
        {
            if (trang == "1")
                return BuildAbsolute(String.Format("TimKiemBaiDang.aspx?TheLoaiID=1&ChuoiTimKiem={0}", chuoiTimKiem));
            return BuildAbsolute(String.Format("TimKiemBaiDang.aspx?TheLoaiID=1&ChuoiTimKiem={0}&Trang={1}", chuoiTimKiem, trang));
        }
        public static string DenTrangTimKiem(string chuoiTimKiem)
        {
            return DenTrangTimKiem(chuoiTimKiem, "1");
        }

        public static string DenChuDe(string theLoai, string chuDeID, string trang)
        {
            if (trang == "1")
                return BuildAbsolute(String.Format("DanhSachBaiDang.aspx?TheLoaiID={0}&ChuDeID={1}", theLoai, chuDeID));
            return BuildAbsolute(String.Format("DanhSachBaiDang.aspx?TheLoaiID={0}&ChuDeID={1}&Trang={1}", theLoai, chuDeID, trang));
        }
        public static string DenChuDe(string theLoai, string chuDeID)
        {
            return DenChuDe(theLoai, chuDeID, "1");
        }

        public static string DenTaiKhoan(string maTaiKhoan, string trang)
        {
            if (trang == "1")
                return BuildAbsolute(String.Format("TrangCaNhan.aspx?TaiKhoanID={0}", maTaiKhoan));
            return BuildAbsolute(String.Format("TrangCaNhan.aspx?TaiKhoanID={0}&Trang={1}", maTaiKhoan, trang));
        }
        public static string DenTaiKhoan(string maTaiKhoan)
        {
            return DenTaiKhoan(maTaiKhoan, "1");
        }

        public static string LayHinhAnh(string fileName)
        {
            return BuildAbsolute(String.Format("HinhAnh/{0}", fileName));
        }
        public static string LayViDeo(string fileName)
        {
            return BuildAbsolute(String.Format("ViDeo/{0}", fileName));
        }
        public static string DenBaiDang(string theLoai, string maBaiDang)
        {
            return BuildAbsolute(String.Format("XemBaiDang.aspx?TheLoaiID={0}&BaiDangID={1}", theLoai, maBaiDang));
        }

        public static string DenCapNhatThongTinBaiDang(string maBaiDang, string trang)
        {
            if (trang == "1")
                return BuildAbsolute(String.Format("CapNhatThongTinBaiDang.aspx?BaiDangID={0}", maBaiDang));
            return BuildAbsolute(String.Format("CapNhatThongTinBaiDang.aspx?BaiDangID={0}&Trang={1}", maBaiDang, trang));

        }
        public static string DenCapNhatThongTinBaiDang(string maBaiDang)
        {
            return DenCapNhatThongTinBaiDang(maBaiDang, "1");
        }

        public static string DenBinhLuan(string maBaiDang, string trang)
        {
            if (trang == "1")
                return BuildAbsolute(String.Format("XemBaiDang.aspx?BaiDangID={0}", maBaiDang));
            return BuildAbsolute(String.Format("XemBaiDang.aspx?BaiDangID={0}&Trang={1}", maBaiDang, trang));
        }
        public static string DenBinhLuan(string maBaiDang)
        {
            return DenBinhLuan(maBaiDang, "1");
        }

        public static string TimKiem(string searchString, string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("TimKiemBaiDang.aspx?TheLoaiID=1&ChuoiTimKiem={0}", searchString));
            return BuildAbsolute(String.Format("TimKiemBaiDang.aspx?TheLoaiID=1&ChuoiTimKiem={0}&Trang={1}", searchString, page));
        }
        public static string TimKiem(string searchString)
        {
            return TimKiem(searchString, "1");
        }

        #endregion

        #region QuanLy
        public static string DenQLBaiDang(string _TrangThai, string _Trang)
        {
            if (_Trang == "1")
                return BuildAbsolute(String.Format("QuanLy/QLBaiDang.aspx?TrangThai={0}", _TrangThai));
            else
                return BuildAbsolute(String.Format("QuanLy/QLBaiDang.aspx?TrangThai={0}&Trang={1}", _TrangThai, _Trang));
        }
        public static string DenQLBaiDang(string _TrangThai)
        {
            return DenQLBaiDang(_TrangThai, "1");
        }
        public static string DenQLBaiDangTheLoai(string _TheLoai, string _Trang)
        {
            if (_Trang == "1")
                return BuildAbsolute(String.Format("QuanLy/QLBaiDang.aspx?TheLoai={0}", _TheLoai));
            else
                return BuildAbsolute(String.Format("QuanLy/QLBaiDang.aspx?TheLoai={0}&Trang={1}", _TheLoai, _Trang));
        }
        public static string DenQLBaiDangTheLoai(string _TheLoai)
        {
            return DenQLBaiDangTheLoai(_TheLoai, "1");
        }
        public static string DenQLTaiKhoan(string quyenSuDung, string _Trang)
        {
            if (_Trang == "1")
                return BuildAbsolute(String.Format("QuanLy/QLTaiKhoan.aspx?QuyenSuDung={0}", quyenSuDung));
            else
                return BuildAbsolute(String.Format("QuanLy/QLTaiKhoan.aspx?QuyenSuDung={0}&Trang={1}", quyenSuDung, _Trang));
        }
        public static string DenQLTaiKhoan(string quyenSuDung)
        {
            return DenQLTaiKhoan(quyenSuDung, "1");
        }
        #endregion
    }
}
